/*
 * Created by JFormDesigner on Mon Dec 21 14:03:39 CST 2020
 */

package cn.fourhundredandeighteen.view.TeacherView.teacherInfo;

import cn.fourhundredandeighteen.controller.TeacherController;
import cn.fourhundredandeighteen.view.Component.Button;
import cn.fourhundredandeighteen.view.Component.Container;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Map;

/**
 * @author root
 */
public class teacherUserInfo extends JPanel {
    private final ArrayList<JLabel> jLabels = new ArrayList<>();
    public int num;
    private ArrayList<JTextField> jTextFields = new ArrayList<>();
    private Long Session;
    private TeacherInfo teacherInfo = new TeacherInfo();
    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JTextField textField2;
    private JLabel label3;
    private JTextField textField3;
    private JLabel label4;
    private JTextField textField4;
    private JLabel label5;
    private JTextField textField5;
    private JLabel label6;
    private JTextField textField6;
    private JLabel label7;
    private JTextField textField7;
    private JLabel label8;
    private JTextField textField8;
    private JButton button1;
    private JLabel label9;
    public teacherUserInfo(Long Session) {
        this.Session = Session;
        this.setBackground(new Color(242, 242, 242));
        initComponents();
        getdata();
        TeacherController teacherController = new TeacherController();
        teacherController.teacherInfo(Session);
        textField1.setEditable(false);
        textField2.setEditable(false);
        textField8.setEditable(false);
        System.out.println(teacherController.getCourseStudents(1024L));
    }

    public void getdata() {
        Map<Integer, String[]> integerMap = teacherInfo.getteacherInfo(Session);
        num = integerMap.get(1).length;//计算长度
        jLabels.add(label1);
        jLabels.add(label2);
        jLabels.add(label3);
        jLabels.add(label4);
        jLabels.add(label5);
        jLabels.add(label6);
        jLabels.add(label7);
        jLabels.add(label8);
        jTextFields.add(textField1);
        jTextFields.add(textField2);
        jTextFields.add(textField3);
        jTextFields.add(textField4);
        jTextFields.add(textField5);
        jTextFields.add(textField6);
        jTextFields.add(textField7);
        jTextFields.add(textField8);
        for (int i = 0; i < integerMap.get(1).length; i++) {
            jLabels.get(i).setText(integerMap.get(1)[i]);
            jTextFields.get(i).setText(integerMap.get(2)[i]);
        }
    }

    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        for (int i = 0; i < num; i++) {
            jTextFields.get(i).setText(jTextFields.get(i).getText());
        }

        JOptionPane.showConfirmDialog(null, teacherInfo.setTeacherInfo(jTextFields), "提示", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE);
        //    label9.setText(infoSet.setStudentInfo(jTextFields));
        //    label9.setForeground(Color.red);
        Container.getInstance().upDatePage();
        this.getdata();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        textField2 = new JTextField();
        label3 = new JLabel();
        textField3 = new JTextField();
        label4 = new JLabel();
        textField4 = new JTextField();
        label5 = new JLabel();
        textField5 = new JTextField();
        label6 = new JLabel();
        textField6 = new JTextField();
        label7 = new JLabel();
        textField7 = new JTextField();
        label8 = new JLabel();
        textField8 = new JTextField();
        button1 = new Button();
        label9 = new JLabel();

        //======== this ========
        setLayout(new GridBagLayout());
        ((GridBagLayout) getLayout()).columnWidths = new int[]{87, 69, 0, 0, 207, 0};
        ((GridBagLayout) getLayout()).rowHeights = new int[]{43, 55, 55, 51, 55, 55, 54, 55, 53, 37, 0};
        ((GridBagLayout) getLayout()).columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};
        ((GridBagLayout) getLayout()).rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

        //---- label1 ----
        label1.setText("text");
        label1.setMaximumSize(new Dimension(23, 25));
        add(label1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField1, new GridBagConstraints(2, 1, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label2 ----
        label2.setText("text");
        add(label2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField2, new GridBagConstraints(2, 2, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label3 ----
        label3.setText("text");
        add(label3, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField3, new GridBagConstraints(2, 3, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label4 ----
        label4.setText("text");
        add(label4, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField4, new GridBagConstraints(2, 4, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label5 ----
        label5.setText("text");
        add(label5, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField5, new GridBagConstraints(2, 5, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label6 ----
        label6.setText("text");
        add(label6, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField6, new GridBagConstraints(2, 6, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label7 ----
        label7.setText("text");
        add(label7, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField7, new GridBagConstraints(2, 7, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- label8 ----
        label8.setText("text");
        add(label8, new GridBagConstraints(1, 8, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 15), 0, 0));
        add(textField8, new GridBagConstraints(2, 8, 3, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 25, 0), 0, 0));

        //---- button1 ----
        button1.setText("\u4fee\u6539");
        button1.addActionListener(e -> button1ActionPerformed(e));
        add(button1, new GridBagConstraints(2, 9, 2, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 0, 15), 0, 0));
        add(label9, new GridBagConstraints(4, 9, 1, 1, 0.0, 0.0,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                new Insets(0, 0, 0, 0), 0, 0));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
